<template>
    <el-dialog
        :before-close="resetForm"
        :close-on-click-modal="false"
        :visible.sync="visible"
        append-to-body
        title="编辑流程类型信息"
        width="860px"
    >
        <div class="edit_page_div">
            <el-form ref="form" :model="form" :rules="rules" :show-message="false" inline label-width="100px">
                <el-form-item label="流程编号" prop="flowableCode">
                    <el-input v-model="form.flowableCode" style="width: 300px;"></el-input>
                </el-form-item>
                <el-form-item label="流程名称" prop="flowableName">
                    <el-input v-model="form.flowableName" style="width: 300px;"></el-input>
                </el-form-item>
                <el-form-item label="处理类名" prop="className">
                    <el-input v-model="form.className" style="width: 300px;"></el-input>
                </el-form-item>
                <el-form-item label="处理方法" prop="dealMethod">
                    <el-input v-model="form.dealMethod" style="width: 300px;"></el-input>
                </el-form-item>
                <el-form-item label="提交方法" prop="applyMethod">
                    <el-input v-model="form.applyMethod" style="width: 300px;"></el-input>
                </el-form-item>
                <el-form-item label="通过方法" prop="adoptMethod">
                    <el-input v-model="form.adoptMethod" style="width: 300px;"></el-input>
                </el-form-item>
                <el-form-item label="拒绝方法" prop="rebutMethod">
                    <el-input v-model="form.rebutMethod" style="width: 300px;"></el-input>
                </el-form-item>
                <el-form-item label="撤回方法" prop="recallMethod">
                    <el-input v-model="form.recallMethod" style="width: 300px;"></el-input>
                </el-form-item>
                <el-form-item label="编辑页" prop="editPath">
                    <el-input v-model="form.editPath" style="width: 700px;"></el-input>
                </el-form-item>
            </el-form>
            <div class="edit_button">
                <el-button v-loading.fullscreen.lock="loading" type="primary" @click="submit">保 存</el-button>
                <el-button type="primary" @click="resetForm">取 消</el-button>
            </div>
        </div>
    </el-dialog>
</template>

<script>
import RadiosOption from "@/components/radio/radiosOption";

export default {
    name: "flowTypeEdit",
    components: {RadiosOption},
    props: {
        visible: Boolean,
        id: String,
    },
    data() {
        return {
			height: '200px',
            loading: false,
            form: {
                flowableCode: '',
                flowableName: '',
                className: '',
                dealMethod: 'deal',
                applyMethod: 'apply',
                adoptMethod: 'Adopt',
                rebutMethod: 'Rebut',
                recallMethod: 'Recall',
                editPath: 'Detail',
            },
            rules: {
                flowableCode: [{required: true, message: '', trigger: 'change'}],
                flowableName: [{required: true, message: '', trigger: 'change'}],
                className: [{required: true, message: '', trigger: 'change'}],
                dealMethod: [{required: true, message: '', trigger: 'change'}],
                applyMethod: [{required: true, message: '', trigger: 'change'}],
                adoptMethod: [{required: true, message: '', trigger: 'change'}],
                rebutMethod: [{required: true, message: '', trigger: 'change'}],
                recallMethod: [{required: true, message: '', trigger: 'change'}],
                editPath: [{required: true, message: '', trigger: 'change'}],
            },
        }
    },
    watch: {
        visible(newVal) {
            if (newVal) {
                if (this.id) {
                    this.getData();
                }
            }
        }
    },
    methods: {
        getData() {
            this.loading = true;
            this.$axios.get('/CHILD_SYSTEM/baseFlowType/getOneEntity/' + this.id).then(res => {
                this.form = res.data;
                this.loading = false;
            }).catch(() => {
                this.loading = false;
            })
        },
        submit() {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.loading = true;
                    this.$axios.post("/CHILD_SYSTEM/baseFlowType/" + (this.id ? "update" : "insert"), this.form).then(res => {
                        this.resetForm();
                        this.$message.success(res.message);
                        this.loading = false;
                    }).catch(() => {
                        this.loading = false;
                    })
                } else {
                    this.$message.error('表单填写有误');
                    return false;
                }
            });
        },
        resetForm() {
            this.$refs.form.resetFields();
            this.form = this.$options.data().form;
            this.$emit('update:visible', false);
            this.$emit('refreshList');
        },
    }
}
</script>

<style scoped>

</style>